package com.feonix.common.view.head;

import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.springframework.web.servlet.tags.RequestContextAwareTag;

import com.feonix.common.BaseInfo;
import com.feonix.common.listener.UserSessionInfo;
import com.feonix.common.util.StringUtil;
import com.feonix.common.view.component.ComponentConfiger;

public class HeadTag extends RequestContextAwareTag {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Map<String, String> componentMap = new LinkedHashMap<String, String>();

	private StringBuffer sb = new StringBuffer();

	private String pagetype = "";

	private String tree = "";

	private String calendar = "";

	private String validity = "";

	private String layout = "";

	private String dialog = "";

	private String grid = "";

	private String tabs = "";

	private String menu = "";

	private String message = "";

	private String progressbar = "";

	private String cookie = "";

	private String placeholder = "";

	private String iconfont = "";

	private String scrollup = "";

	private String upload = "";

	private String multifileupload = "";

	private String cloudfile = "";

	private String cloudfile_image_clip = "";

	private String select = "";

	private String multiselect = "";

	private String loadmask = "";

	private String tip = "";

	private String json = "";

	private String checkpwd = "";

	private String highlighter = "";

	private String editor = "";

	private String toggle = "";

	private String ipass = "";

	private String accordion = "";

	private String security = "";

	private String bootstrap = "";

	public HeadTag() {
		this.componentMap.put("global", "true");
	}

	protected int doStartTagInternal() throws Exception {
		this.pageContext.setAttribute("contextPath", BaseInfo.getContextPath());
		this.pageContext.setAttribute("currentUser", UserSessionInfo.getCurrentUser());
		HashSet<String> hashSet = new HashSet<String>();
		Set<Entry<String, String>> componentMapSet = this.componentMap.entrySet();
		for (Map.Entry<String, String> entry : componentMapSet) {
			if ("true".equalsIgnoreCase(entry.getValue())) {
				this.sb.append(ComponentConfiger.buildCode(entry.getKey(), hashSet));
			}
		}

		try {
			this.pageContext.getOut().write(String.valueOf(this.sb.toString()));
			StringUtil.cleanStringBuffer(new StringBuffer[] { this.sb });
		} catch (Exception exception) {
			this.logger.error("模板输出失败", exception);
		}
		return 1;
	}

	public String getPagetype() {
		return this.pagetype;
	}

	public void setPagetype(String pagetype) {
		this.pagetype = pagetype;
		if (pagetype.equals("page"))
			this.componentMap.put("global-page", "true");
		else if (pagetype.equals("dialog"))
			this.componentMap.put("global-dialog", "true");
	}

	public String getTree() {
		return this.tree;
	}

	public void setTree(String tree) {
		this.tree = tree;
		this.componentMap.put("tree", tree);
	}

	public String getCalendar() {
		return this.calendar;
	}

	public void setCalendar(String calendar) {
		this.calendar = calendar;
		this.componentMap.put("calendar", calendar);
	}

	public String getValidity() {
		return this.validity;
	}

	public void setValidity(String validity) {
		this.validity = validity;
		this.componentMap.put("validity", validity);
	}

	public String getDialog() {
		return this.dialog;
	}

	public void setDialog(String dialog) {
		this.dialog = dialog;
		this.componentMap.put("dialog", dialog);
	}

	public String getGrid() {
		return this.grid;
	}

	public void setGrid(String grid) {
		this.grid = grid;
		this.componentMap.put("grid", grid);
	}

	public String getTabs() {
		return this.tabs;
	}

	public void setTabs(String tabs) {
		this.tabs = tabs;
		this.componentMap.put("tabs", tabs);
	}

	public String getMenu() {
		return this.menu;
	}

	public void setMenu(String menu) {
		this.menu = menu;
		this.componentMap.put("menu", menu);
	}

	public String getMessage() {
		return this.message;
	}

	public void setMessage(String message) {
		this.message = message;
		this.componentMap.put("message", message);
	}

	public String getLayout() {
		return this.layout;
	}

	public void setLayout(String layout) {
		this.layout = layout;
		this.componentMap.put("layout", layout);
	}

	public String getProgressbar() {
		return this.progressbar;
	}

	public void setProgressbar(String progressbar) {
		this.progressbar = progressbar;
		this.componentMap.put("progressbar", progressbar);
	}

	public String getCookie() {
		return this.cookie;
	}

	public void setCookie(String cookie) {
		this.cookie = cookie;
		this.componentMap.put("cookie", cookie);
	}

	public String getPlaceholder() {
		return this.placeholder;
	}

	public void setPlaceholder(String placeholder) {
		this.placeholder = placeholder;
		this.componentMap.put("placeholder", placeholder);
	}

	public String getIconfont() {
		return this.iconfont;
	}

	public void setIconfont(String iconfont) {
		this.iconfont = iconfont;
		this.componentMap.put("iconfont", iconfont);
	}

	public String getScrollup() {
		return this.scrollup;
	}

	public void setScrollup(String scrollup) {
		this.scrollup = scrollup;
		this.componentMap.put("scrollup", scrollup);
	}

	public String getUpload() {
		return this.upload;
	}

	public void setUpload(String upload) {
		this.upload = upload;
		this.componentMap.put("upload", upload);
	}

	public String getMultifileupload() {
		return this.multifileupload;
	}

	public void setMultifileupload(String multifileupload) {
		this.multifileupload = multifileupload;
		this.componentMap.put("multifileupload", multifileupload);
	}

	public String getSelect() {
		return this.select;
	}

	public void setSelect(String select) {
		this.select = select;
		this.componentMap.put("select", select);
	}

	public String getMultiselect() {
		return this.multiselect;
	}

	public void setMultiselect(String multiselect) {
		this.multiselect = multiselect;
		this.componentMap.put("multiselect", multiselect);
	}

	public String getLoadmask() {
		return this.loadmask;
	}

	public String getTip() {
		return this.tip;
	}

	public void setLoadmask(String loadmask) {
		this.loadmask = loadmask;
		this.componentMap.put("loadmask", loadmask);
	}

	public void setTip(String tip) {
		this.tip = tip;
		this.componentMap.put("tip", tip);
	}

	public String getJson() {
		return this.json;
	}

	public void setJson(String json) {
		this.json = json;
		this.componentMap.put("json", json);
	}

	public String getCheckpwd() {
		return this.checkpwd;
	}

	public void setCheckpwd(String checkpwd) {
		this.checkpwd = checkpwd;
		this.componentMap.put("checkpwd", checkpwd);
	}

	public String getHighlighter() {
		return this.highlighter;
	}

	public void setHighlighter(String highlighter) {
		this.highlighter = highlighter;
		this.componentMap.put("highlighter", highlighter);
	}

	public String getEditor() {
		return this.editor;
	}

	public void setEditor(String editor) {
		this.editor = editor;
		this.componentMap.put("editor", editor);
	}

	public String getToggle() {
		return this.toggle;
	}

	public void setToggle(String toggle) {
		this.toggle = toggle;
		this.componentMap.put("toggle", toggle);
	}

	public String getIpass() {
		return this.ipass;
	}

	public void setIpass(String ipass) {
		this.ipass = ipass;
		this.componentMap.put("ipass", ipass);
	}

	public String getAccordion() {
		return this.accordion;
	}

	public void setAccordion(String accordion) {
		this.accordion = accordion;
		this.componentMap.put("accordion", accordion);
	}

	public String getSecurity() {
		return this.security;
	}

	public void setSecurity(String security) {
		this.security = security;
		this.componentMap.put("security", security);
	}

	public String getCloudfile() {
		return this.cloudfile;
	}

	public void setCloudfile(String cloudfile) {
		this.cloudfile = cloudfile;
		this.componentMap.put("cloudfile", cloudfile);
	}

	public String getCloudfile_image_clip() {
		return this.cloudfile_image_clip;
	}

	public void setCloudfile_image_clip(String cloudfile_image_clip) {
		this.cloudfile_image_clip = cloudfile_image_clip;
		this.componentMap.put("cloudfile_image_clip", cloudfile_image_clip);
	}

	public String getBootstrap() {
		return this.bootstrap;
	}

	public void setBootstrap(String bootstrap) {
		this.bootstrap = bootstrap;
		this.componentMap.put("bootstrap", bootstrap);
	}

}
